<?php

namespace app\common\model\xiservice;

use think\Model;


class Comment extends Model
{

    

    

    // 表名
    protected $name = 'xiservice_order_comment';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
            'images_arr',
            'createtime_text'
    ];
    

    
    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i", $value) : $value;
    }


    public function getImagesArrAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['images']) ? $data['images'] : '');
        $array = [];
        if($value){
            $list = explode(',', $value);
            for($i=0;$i<count($list);$i++){
                array_push($array, cdnurl($list[$i],true));
            }
        }
        return $array;      
    }



    public function user()
    {
        return $this->belongsTo('app\common\model\xiservice\User', 'user_id', 'user_id', [], 'LEFT')->setEagerlyType(0);
    }
}
